package config

import (
	"tlsx"

	"github.com/cloudwego/hertz/pkg/app/server"
	"github.com/cloudwego/hertz/pkg/network/netpoll"
	"github.com/cloudwego/hertz/pkg/protocol/suite"
	quic "github.com/memento/hertz/quic-go/network"
	http3 "github.com/memento/hertz/quic-go/server"
	"github.com/memento/hertz/quic-go/server/factory"
)

func NewQuic(addr string) *server.Hertz {
	cfg := tlsx.TlsCfg(suite.HTTP3, suite.HTTP2, suite.HTTP1)
	h := server.New(server.WithALPN(true),
		server.WithTLS(cfg),
		server.WithTransport(quic.NewTransporter),
		server.WithSenseClientDisconnection(true),
		server.WithAltTransport(netpoll.NewTransporter),
		server.WithHostPorts(addr),
	)
	h.AddProtocol(suite.HTTP3, factory.NewServerFactory(&http3.Option{}))
	return h
}
